package com.osleague.demo.controller;

import com.osleague.demo.domain.User;
import com.osleague.demo.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by Yif Zhan on 2015/10/29.
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView index(Map<String, Object> model) {

        User user = userService.getUserById(1);
        model.put("user", user);

        return new ModelAndView("user/index", model);
    }

    @RequestMapping(value = "/{id}")
    @ResponseBody
    public User getUser(@PathVariable(value = "id") long id) {
        return userService.getUserById(id);
    }

}
